/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aqu.controlador.Administrador;

import aqu.bean.generico.BeanGenerico;
import aqu.persistencia.Dao.Administracion.SegMenuManager;
import aqu.persistencia.entity.SegMenu;
import aqu.persistencia.utilidad.MessagesController;
import com.icesoft.faces.component.ext.RowSelectorEvent;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

/**
 *
 * @author AQU
 */
@ManagedBean(name = "menuController")
@ViewScoped
public class MenuController extends BeanGenerico {

    private SegMenu menu;
    private List<SegMenu> lista;
    private SegMenuManager SegMenuManager = new SegMenuManager();
    private boolean panelvisible;

    public MenuController() {

        menu = new SegMenu();
        lista = SegMenuManager.getList();
    }

    public boolean isPanelvisible() {
        return panelvisible;
    }

    public void setPanelvisible(boolean panelvisible) {
        this.panelvisible = panelvisible;
    }

    public void llamarPanelvisible(ActionEvent event) {
        panelvisible = !panelvisible;
    }

    public List<SegMenu> getLista() {
        lista = SegMenuManager.getListOrdenado("segModuloMen");
        return lista;
    }

    public void setLista(List<SegMenu> lista) {
        this.lista = lista;
    }

    public void nuevo(ActionEvent actionEvent) {
        menu = new SegMenu();
    }

    public String eliminar() {
        try {
            SegMenu menuTemp = (SegMenu) (menu);
            if (SegMenuManager.delete(menuTemp) == false) {
                llamarPanelvisible(null);

            }
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }

        return "index";

    }

    public void insertar(ActionEvent actionEvent) {
        try {
            menu.setSegCodigoMen(MessagesController.obtenerkeyautomaticosinceros("seg_menu", "SEG_CODIGO_MEN"));
            if (SegMenuManager.create(menu) == false) {
                llamarPanelvisible(null);

            }
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }

    }

    public void modificar(ActionEvent actionEvent) {
        try {
            if (SegMenuManager.update(menu) == false) {
                llamarPanelvisible(null);

            }
        } catch (Exception e) {
            MessagesController.addInfo("Mensaje de error :", e.getMessage());
            llamarPanelvisible(null);
        }


    }

    public void rowSelectionListener(RowSelectorEvent event) {
        menu = lista.get(event.getRow());

    }

    public SegMenuManager getSegMenuManager() {
        return SegMenuManager;
    }

    public void setSegMenuManager(SegMenuManager SegMenuManager) {
        this.SegMenuManager = SegMenuManager;
    }

    public SegMenu getMenu() {
        return menu;
    }

    public void setMenu(SegMenu menu) {
        this.menu = menu;
    }

    

    
    
}
